$(function () {
    $('#userForm').datagrid({
    	width:400,
    	title:'用户列表',
    	iconCls:'icon-search',
    	//url:'/UserDbRController/queryList',
    	pagination:true,
    	columns:[[
    	   {
    		field:'id',   
    		title:'id',	
    	   },
    	   {
       		field:'name',   
       		title:'账号',	
       	   },  {
    		field:'password',   
    		title:'密码',	
    	   },
    	          
    	          
       ]],
    	
    }
    		
    )
	
});
function newUser(){
	
	$('#dlg').dialog('open').dialog('setTitle','New User');
	$('#fm').form('clear');
	url = '../UserDbRController/insert';
}
function editUser(){
var row = $('#dg').datagrid('getSelected');
if (row){
	$('#dlg').dialog('open').dialog('setTitle','Edit User');
	$('#fm').form('load',row);
	url = '../UserDbRController/update?id='+row.id;
}
}
function saveUser(){
	$('#fm').form('submit',{
		url:url,
		onSubmit: function(){
			return $(this).form('validate');
		},
		success: function(result){		
				$('#dlg').dialog('close');		// close the dialog
				$('#dg').datagrid('reload');	// reload the user data
				alert(result);
			}
		}
	);
}
function destroyUser(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
		$.messager.confirm('Confirm','Are you sure you want to destroy this user?',function(r){
			if (r){
				$.post('../UserDbRController/delete',{id:row.id},function(result){
					alert(result);
					$('#dg').datagrid('reload');
				});
			}
		});
	}
}
/*
$.parser.auto = false;
$.parser.onComplete = function () {
	alert('UI解析完毕！');
};*/